﻿using BLL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using Model;

namespace EstateappraisalApi.Controllers
{
    /// <summary>
    /// 角色管理
    /// </summary>
    public class RolesController : ApiController
    {
        RolesBLL bll = new RolesBLL();

        // GET api/roles
        /// <summary>
        /// 显示所有角色
        /// </summary>
        /// <returns></returns>
        public IEnumerable<Roles> Get()
        {
            return bll.ShowRoles();
        }

        // GET api/roles/5
        public string Get(int id)
        {
            return "value";
        }

        // POST api/roles
        /// <summary>
        /// 添加角色信息
        /// </summary>
        /// <param name="value"></param>
        public int Post([FromBody]Roles mod)
        {
            mod.roles_CreatePeople = "1";
            mod.roles_CreateTime = DateTime.Now;
            if (bll.AddRoles(mod))
            {
                return 1;
            }
            else
            {
                return 0;
            }
        }


        // PUT api/department/5
        /// <summary>
        /// 修改角色信息
        /// </summary>
        /// <param name="id"></param>
        /// <param name="value"></param>
        public int Put([FromBody]Roles m)
        {
            m.roles_CreatePeople = "1";
            m.roles_CreateTime = DateTime.Now;
            if (bll.UpdRoles(m, m.roles_Id))
            {
                return 1;
            }
            else
            {
                return 0;
            }

        }


        /// <summary>
        /// 删除角色信息
        /// </summary>
        /// <param name="id"></param>
        [HttpDelete]
        public int Delete(int id)
        {
            Roles m = new Roles();
            m.roles_Id = id;
            if (bll.DelRoles(m))
            {
                return 1;
            }
            else
            {
                return 0;
            }

        }
    }
}
